package com.beta.platform.rest.constant.dic;

import lombok.Getter;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Locale;


/**
 * 语言标识枚举
 *
 * @author star.qin
 * @version 1.0
 * @date 2020/6/24 15:47
 */
@SuppressWarnings({"PMD", "all"})
public enum LanguageEnum implements DictEnum {
    CHINESE_CHINA("zh-CN", "中文简体", "zh,cn,zh-CN", 1),
    ENGLISH("en", "英语", "en,en-US,en-GB,en-IE,en-CA,en-AU,en-NZ", 2),
    CHINESE_FAN_TI("zh-FT", "中文繁体", "zh-TW,zh-HK,zh-SG,zh-FT,zh-CHT", 3),
    FRENCH("fr", "法语", "fr,fr-BE,fr-CA,fr-FR,fr-LU,fr-CH,fr_FI", 4),
    GERMAN("de", "德语", "de,de-AT,de-DE,de-LI,de-LU,de-CH", 5),
    GREEK("el", "希腊语", "el,el-GR", 6),
    ITALIAN("it", "意大利语", "it,it-IT,it-CH", 7),
    JAPANESE("ja", "日语", "ja,ja-JP", 8),
    KOREAN("ko-KR", "韩语", "ko,kr,ko_KR,Korea", 9),
    RUSSIAN("ru", "俄语", "ru,ru-RU", 10);

    @Override
    public int getIntValue() {
        return languageIntCode;
    }

    @Override
    public String getCode() {
        return languageCode;
    }

    private String languageCode;

    @Getter
    private String languageName;

    @Getter
    private Integer languageIntCode;
    @Getter
    private List<String> languageGroup;


    LanguageEnum(String languageCode, String languageName, String languageGroup, Integer languageIntCode) {
        this.languageCode = languageCode;
        this.languageName = languageName;
        this.languageGroup = Collections.unmodifiableList(Arrays.asList(languageGroup.split(",")));
        this.languageIntCode = languageIntCode;
    }


    LanguageEnum(String languageCode, String languageName, Integer languageIntCode) {
        this.languageCode = languageCode;
        this.languageName = languageName;
        this.languageIntCode = languageIntCode;
    }

    public Locale convertToLocale() {
        return convertToLocale(this);
    }

    public static Locale convertToLocale(LanguageEnum languageEnum) {
        switch (languageEnum) {
            case CHINESE_CHINA:
                return Locale.CHINESE;
            case ENGLISH:
                return Locale.ENGLISH;
            case CHINESE_FAN_TI:
                return Locale.TAIWAN;
            case FRENCH:
                return Locale.FRENCH;
            case JAPANESE:
                return Locale.JAPANESE;
            case KOREAN:
                return Locale.KOREAN;
            case ITALIAN:
                return Locale.ITALIAN;
            case GERMAN:
                return Locale.GERMAN;
//            case  RUSSIAN:
//                return   Locale.;
        }
        return Locale.ENGLISH;
    }
}
